﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>工艺名称以及加工单价设置</title>
    <link rel="stylesheet" href="~/Content/bootstrap.min.css" />
    <link rel="stylesheet" href="~/Content/bootstrap-table.css" />
    <link rel="stylesheet" href="~/Content/style.css" />
    <link rel="stylesheet" href="~/Content/alertify.min.css" />
    <link rel="stylesheet" href="~/Content/themes/default.min.css" />
    <style>
        h2 {
            line-height: normal;
            margin-top: 0px;
        }

        #text {
            border-left: 1px solid #ccc !important;
        }
    </style>
</head>
<body>
    @Html.Action("Top", "Home")
    <div class="top_search">
        <h2>工序管理</h2>
        <form class="form1" onsubmit="InitTable(); return false;">
            <select id="manager_id" style="display:none;"><option value="0">默认数据</option></select>
            <input type="text" id="text" placeholder="输入工序名称、助记符">
            <input type="submit" id="btn" class="jb" value="查询">
        </form>
        <div class="tool"><a href="#" class="jb" id="add">增加</a><a href="#" class="jb" id="edit">修改</a><a href="#" class="jb" onclick="onDelteItem();">删除</a></div>
    </div>
    <div id="box_add">
        <h2><i>新增工艺工序</i><span>×</span></h2>
        <div><span>工序名称：</span><input name="name" type="text" data-type="text" required maxlength="50" data-error="工序名称不能为空且长度不能超过50个字符!"></div>
        <div><span>工序价格：</span><input name="price" data-type="number" type="text" required data-error="工序价格不能为空且必须全部为数字！"></div>
        <div><span>按重量算：</span><select name="isCalWeight"><option value="false">否</option><option value="true">是</option></select></div>
        <div><span>是否热处理：</span><select name="isDealHot"><option value="false">否</option><option value="true">是</option></select></div>
        <div><span>是否表面处理：</span><select name="isDealSurface"><option value="false">否</option><option value="true">是</option></select></div>
        <div><span>备注说明：</span><input name="remark" type="text" maxlength="50" data-type="text" data-error="备注名长度不能超过50个字符!"></div>
        <div><span>拼音助记符：</span><input name="alias" type="text" data-type="text" maxlength="50" data-error="拼音助记符长度不能超过50个字符！"></div>
        <p><input type="submit" onclick="onAddSave()" class="jb" value="保存" /><input class="jb" type="button" value="返回"></p>
    </div>

    <div class="clear"></div>

    <div class="table1">
        <table data-show-export="true"></table>
    </div>

    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script src="~/Scripts/bootstrap-table.js"></script>
    <script src="~/Scripts/locale/bootstrap-table-zh-CN.js"></script>
    <script src="~/Scripts/uilts.js"></script>
    <script src="~/Scripts/extensions/export/bootstrap-table-export.js"></script>
    <script src="~/Scripts/alertify.min.js"></script>
    <script src="~/Scripts/selectuser.js"></script>
    <script>
        var $table = $('table');
        function InitTable(pageIndex, pageSize) {
            if (typeof pageIndex == "object") {
                pageIndex = undefined;
            }
            $table.bootstrapTable('destroy');
            $table.bootstrapTable({
                method: "post",  //使用get请求到服务器获取数据
                url: "/Gongxu/listdata", //获取数据的Servlet地址
                striped: true,  //表格显示条纹
                pagination: true, //启动分页
                pageSize: pageSize == null ? 10 : pageSize,  //每页显示的记录数
                pageNumber: pageIndex == null ? 1 : pageIndex, //当前第几页
                pageList: [10, 20, 50, 100, 250],  //记录数可选列表
                search: false,  //是否启用查询
                showColumns: true,  //显示下拉框勾选要显示的列
                showRefresh: true,  //显示刷新按钮
                sidePagination: "server", //表示服务端请求
                sortName: "ID",
                //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
                //设置为limit可以获取limit, offset, search, sort, order
                queryParamsType: "undefined",
                queryParams: function queryParams(params) {   //设置查询参数
                    var param = {
                        PageIndex: params.pageNumber,
                        PageSize: params.pageSize,
                        search: $("#text").val().trim(),
                        sorter: params.sortName + " " + params.sortOrder,
                        manager_id: $("select#manager_id").val()
                    };
                    return param;
                },
                columns: [
                    {
                        field: 'name',
                        title: "工序名称",
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'price',
                        title: '价格(元/小时)',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'isCalWeight',
                        title: '按重量算加工费',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            if (value == true) {
                                return '<img src="/Images/checkbox.gif" alt="'+value+'"/>';
                            } else {
                                return '<img src="/Images/error.gif" alt="' + value + '"/>';
                            }
                        }
                    },
                    {
                        field: 'isDealHot',
                        title: '是否热处理',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value,row, index) {
                            if (value == true) {
                                return '<img src="/Images/checkbox.gif" alt="' + value + '"/>';
                            } else {
                                return '<img src="/Images/error.gif" alt="' + value + '"/>';
                            }
                        }
                    },
                    {
                        field: 'isDealSurface',
                        title: '是否表面处理',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            if (value == true) {
                                return '<img src="/Images/checkbox.gif" alt="' + value + '"/>';
                            } else {
                                return '<img src="/Images/error.gif" alt="' + value + '"/>';
                            }
                        }
                    },
                    {
                        field: 'remark',
                        title: '备注说明',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'alias',
                        title: '拼音助记符',
                        align: 'center',
                        valign: 'middle'
                    }
                ],
                onLoadSuccess: function () {
                    $('table tr:even').find('td').css("background", "#e9f3ff");
                    $('table tr').click(function () {
                        uncheckAll($table);
                        $('table tr').removeClass("act");
                        $(this).addClass("act");
                        $table.bootstrapTable('check', $(this).attr("data-index"));
                    });
                }
            });
        }

        InitTable();

    </script>
    <script src="~/Scripts/tableExport.js"></script>
    <script src="~/Scripts/html2canvas.js"></script>
    <script src="~/Scripts/jquery.base64.js"></script>
    <script src="~/Scripts/menu.js"></script>
    <script>
        $('#add,#edit').click(function () {
            EmptyForm("#box_add");
            if ($(this).attr("id") == "edit") {
                onEditItem();
            } else {
                $('#box_add').css("display", "block");
            }
        });
        $('#box_add').find('p input').eq(1).click(function () {
            $('#box_add').css("display", "none");
            update_id = 0;
        });
        $('#box_add').find('h2 span').click(function () {
            $('#box_add').css("display", "none");
            update_id = 0;
        });
    </script>
    <script>
        var update_id = 0;
        function onAddSave() {

            if (!ValidateModel("#box_add", function (error) {
                alertify.error(error);
            })) {
                return;
            };
            var data = GetFormData("#box_add");
            data["id"] = update_id;
            PostApi("/Gongxu/adddata", JSON.stringify(data), function (result) {
                if (result.code == 0) {
                    if (update_id == 0) {
                        alertify.success("添加成功!");
                        EmptyForm("#box_add");
                    } else {
                        alertify.success("修改成功!");
                    }
                    InitTable();
                } else {
                    alertify.error(result.ErrorMessage);
                }
            }, function () {
                if (update_id == 0) {
                    alertify.error("添加失败!");
                } else {
                    alertify.error("修改失败!");
                }
            },"application/json");
        }

        function onDelteItem() {
            var selected = $table.bootstrapTable('getSelections');
            if (selected != undefined && selected.length > 0) {
                alertify.confirm("提示", "确认删除工序【" + selected[0].name + "】?", function () {
                    PostApi("/Gongxu/DeleteItem", { id: selected[0].ID }, function (result) {
                        if (result.code == 0) {
                            alertify.success("删除成功!");
                            InitTable();
                        } else {
                            alertify.error(result.ErrorMessage);
                        }
                    }, function () { });
                }, function () { });
            } else {
                alertify.error("请选择需要删除的行!");
            }
        }

        function onEditItem() {
            var selected = $table.bootstrapTable('getSelections');
            if (selected != undefined && selected.length > 0) {
                update_id = selected[0].ID;
                $("#box_add input[name='name']").val(selected[0].name);
                $("#box_add input[name='alias']").val(selected[0].alias);
                $("#box_add input[name='remark']").val(selected[0].remark);
                $("#box_add input[name='price']").val(selected[0].price);
                console.log(selected[0].isCalWeight);
                $("#box_add select[name='isCalWeight']").val(selected[0].isCalWeight.toString());
                $("#box_add select[name='isDealHot']").val(selected[0].isDealHot.toString());
                $("#box_add select[name='isDealSurface']").val(selected[0].isDealSurface.toString());

                $('#box_add').css("display", "block");

            } else {
                alertify.error("请选择需要编辑的行!");
            }
        }
    </script>
</body>
</html>
